package com.base.project.resultMapUtil;

import com.alibaba.fastjson.JSONObject;

import java.util.Map;

/**
 * @ProjectName: ResultMapUtil
 * @Package: com.base.project.resultMapUtil
 * @Description: 返回信息封装
 * @Author: Z.G.C
 * @CreateDate: 2019/7/15 4:55 PM
 * @UpdateUser: Z.G.C
 * @UpdateDate: 2019/7/15 4:55 PM
 * @UpdateRemark: The modified content
 * @Version: 1.0
 * <p>Copyright: Copyright (c) 2019</p>
 */
public class ResultMapUtil {

    public static ResultMap success(Object object) {
        ResultMap resultMap = new ResultMap();
        resultMap.setCode(ResultCode.valueOf("SUCCESS").getCode());
        resultMap.setMsg(ResultCode.valueOf("SUCCESS").getMsg());
        resultMap.setData(object);
        return resultMap;
    }

    public static ResultMap error() {
        ResultMap resultMap = new ResultMap();
        resultMap.setCode(ResultCode.valueOf("SYSTEM_ERROR").getCode());
        resultMap.setMsg(ResultCode.valueOf("SYSTEM_ERROR").getMsg());
        return resultMap;
    }
    public static ResultMap error(String code, String msg) {
        ResultMap resultMap = new ResultMap();
        resultMap.setCode(code);
        resultMap.setMsg(msg);
        return resultMap;
    }

    public static Map<String, Object> getData(String json){
        Map<String, Object> paramMap = JSONObject.parseObject(json);
        return JSONObject.parseObject((String) paramMap.get("data"));
    }

    public static void main(String[] args) {
        System.out.println(ResultMapUtil.success("ooo"));
        System.out.println( );

    }


}
